home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / examples / infobrws / src / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-18  |  27.9 KB  |  829 lines

  1. //     (C) Copyright Microsoft Corp. 1991.  All rights reserved.
  2. //
  3. //     You have a royalty-free right to use, modify, reproduce and 
  4. //     distribute the Sample Files (and/or any modified version) in 
  5. //     any way you find useful, provided that you agree that 
  6. //     Microsoft has no warranty obligations or liability for any 
  7. //     Sample Application Files which are modified. 
  8.  
  9.  
  10. /****************************************************************************
  11.  
  12.     MODULE    : INIT.C
  13.  
  14.     PURPOSE   : This module contains the functions which do initialization in the program playvfw.
  15.  
  16.     FUNCTIONS :  
  17.                 PlayVFWInit
  18.                 InitVFWStuff
  19.                 CreateVideoWindow
  20.                 InitDeviceVars
  21.                 Morph
  22.                 DrawControl
  23.                 DoNextPage
  24.                 DoPage1
  25.                 ReturnDeviceError
  26.  
  27.  
  28.     COMMENTS  : 
  29.  
  30.     HISTORY   : Created By Steven Molstad 8/20/93.
  31.  
  32. ****************************************************************************/  
  33.  
  34. #include "windows.h"
  35. #include <stdlib.h>
  36. #include "playvfw.h"
  37. #include "proto.h"
  38. #include "mmsystem.h"
  39. #include <digitalv.h>
  40. #include <stdio.h>
  41. #include <time.h>
  42.  
  43. /* Procedure called when the application is loaded for the first time */ 
  44.  
  45. /****************************************************************************
  46.  
  47.     FUNCTION    : PlayVFWInit( HANDLE )
  48.  
  49.     PURPOSE   :   This function initializes the window class for both the main window and for the
  50.                   video playback window on the last page.  It also loads the strings associated with
  51.                   the application.
  52.     
  53.     COMMENTS  :   To achieve the black background I changed the background brush to BLACK_BRUSH.  This is
  54.                   the easiest way to do this.
  55.  
  56.     HISTORY   :    Created by Steven Molstad 6/1/93
  57.  
  58. ****************************************************************************/ 
  59.  
  60. BOOL PlayVFWInit( hInstance )
  61. HANDLE hInstance;
  62. {
  63.     PWNDCLASS   pplayvfwClass;
  64.     PWNDCLASS   pVidWinClass;           
  65.     
  66.     /* Load strings from resource */
  67.     LoadString( hInstance, IDSNAME, (LPSTR)szAppName, 10 );
  68.     LoadString( hInstance, IDSABOUT, (LPSTR)szAbout, 10 );
  69.     MessageLength = LoadString( hInstance, IDSTITLE, (LPSTR)szMessage, 25 );
  70.                                                                   
  71.     // set up a class without a menu.                                                              
  72.                                                                   
  73.     pplayvfwClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  74.  
  75.     pplayvfwClass->hCursor      = LoadCursor( NULL, IDC_ARROW);
  76.     pplayvfwClass->hIcon          = LoadIcon( hInstance, MAKEINTRESOURCE(PLAYVFWICON) );
  77.     pplayvfwClass->lpszMenuName =   NULL;
  78.     pplayvfwClass->lpszClassName  = (LPSTR)szAppName;
  79.     pplayvfwClass->hbrBackground  = (HBRUSH)GetStockObject( BLACK_BRUSH );
  80.     pplayvfwClass->hInstance      = hInstance;
  81.     pplayvfwClass->style          = CS_HREDRAW | CS_VREDRAW;
  82.     pplayvfwClass->lpfnWndProc      = PlayVFWWndProc;
  83.  
  84.     if (!RegisterClass( (LPWNDCLASS)pplayvfwClass ) )
  85.     /* Initialization failed.
  86.      * Windows will automatically deallocate all allocated memory.
  87.      */
  88.     return FALSE;
  89.  
  90.     LocalFree( (HANDLE)pplayvfwClass );            
  91.     
  92.     pVidWinClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  93.  
  94.     pVidWinClass->hCursor      = LoadCursor( NULL, IDC_ARROW);
  95.     pVidWinClass->hIcon          = LoadIcon( hInstance, MAKEINTRESOURCE(PLAYVFWICON) );
  96.     pVidWinClass->lpszMenuName =   NULL;
  97.     pVidWinClass->lpszClassName  = (LPSTR)"VidWin";
  98.     pVidWinClass->hbrBackground  = (HBRUSH)GetStockObject( BLACK_BRUSH );
  99.     pVidWinClass->hInstance      = hInstance;
  100.     pVidWinClass->style          = CS_HREDRAW | CS_VREDRAW;
  101.     pVidWinClass->lpfnWndProc      = VideoWndProc;
  102.  
  103.     if (!RegisterClass( (LPWNDCLASS)pVidWinClass ) )
  104.     /* Initialization failed.
  105.      * Windows will automatically deallocate all allocated memory.
  106.      */
  107.     return FALSE;
  108.  
  109.     LocalFree( (HANDLE)pVidWinClass );
  110.     return TRUE;        /* Initialization succeeded */
  111. }
  112.  
  113. /****************************************************************************
  114.  
  115.     FUNCTION  : InitVFWStuff( HANDLE,HANDLE )
  116.  
  117.     PURPOSE   : This function creates the owner draw buttons for the initial screen and first
  118.                 page of the program.  It also opens the VFW device and the waveaudio device.  All
  119.                 AVI files and wave files for the initial screen and for the first page are opened
  120.                 here.
  121.     
  122.     COMMENTS  : This function also starts the initial video playing.
  123.  
  124.     HISTORY   : Created by Steven Molstad 7/15/93
  125.  
  126. ****************************************************************************/ 
  127.  
  128. BOOL FAR PASCAL InitVFWStuff(hWnd,hInstance)
  129. HWND hWnd;
  130. HANDLE hInstance;
  131. {
  132.     
  133.     RECT Points;
  134.  
  135.     // we are now at page 0 (initialization screen) set the page values as appropriate.
  136.     
  137.     bIsPage0=TRUE;
  138.     bIsPage1=FALSE;
  139.     bIsPage2=FALSE;
  140.  
  141.    
  142.     // open both the VFW device and the waveaudio device.  If they don't open return FALSE, and stop the
  143.     // program from loading.  If there is no sound in the system don't try to load the waveaudio device.
  144.    
  145.      wGlobalDeviceID = OpenVFWDevice(hWnd);   
  146.      
  147.      if (!bNoSound)
  148.            wGlobalAudioDeviceID = OpenWaveDevice();
  149.  
  150.      /* grey menu item first */
  151.      /* enable second */
  152.  
  153.      if (!wGlobalDeviceID)
  154.         {
  155.          MessageBox(GetFocus(),"Can't open device","ERROR",MB_OK);
  156.          
  157.          return FALSE;
  158.          }
  159.      
  160.      if (!bNoSound)
  161.            if (!wGlobalAudioDeviceID)
  162.                  {
  163.                   MessageBox(GetFocus(),"Can't open Audio device","ERROR",MB_OK);
  164.          
  165.                   return FALSE;
  166.                  }
  167.      
  168.      // Get the directories for the wave files, ini files and AVI files.
  169.      
  170.      GetDirFromIni(lpDirs,"playvfw");
  171.  
  172.      // Initialize the lpDevice1 memory which is associated with button1 on the first page.
  173.  
  174.      InitDeviceVars(lpDevice1);
  175.                                         
  176.      // retrieve the device information for button1 as well as where the button is located in the Points structure.
  177.                                              
  178.      if(!GetStuffFromIni(lpDevice1,1,&Points))
  179.           return FALSE;
  180.      
  181.      // Create the owner draw button representing button1 on the first page.  Use the coordinates retrieved
  182.      // from the playvfw.ini file.
  183.      
  184.      lpDevice1->hWnd = CreateWindow((LPSTR)"button",
  185.             (LPSTR)"Text window",
  186.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  187.             Points.left,   /*  x - ignored for tiled windows */
  188.             Points.top,    /*  y - ignored for tiled windows */
  189.             Points.right,     /* cx - ignored for tiled windows */
  190.             Points.bottom,      /* cy - ignored for tiled windows */
  191.             (HWND)hWnd,       /*parent */
  192.             (HMENU)IDC_TEXT,       /* use class menu */
  193.             (HANDLE)hInstance, /* handle to window instance */
  194.                         (LPSTR)NULL        /* no params to pass on */
  195.             );                  
  196.             
  197.      // Initialize the lpDevice2 memory which is associated with button1 on the first page.
  198.      
  199.      InitDeviceVars(lpDevice2);
  200.      
  201.     // retrieve the device information for button2 as well as where the button is located in the Points structure.
  202.     
  203.      GetStuffFromIni(lpDevice2,2,&Points);
  204.  
  205.     // Create the owner draw button representing button2 on the first page.  Use the coordinates retrieved
  206.      // from the playvfw.ini file.
  207.  
  208.      lpDevice2->hWnd = CreateWindow((LPSTR)"button",
  209.             (LPSTR)"Audio Button",
  210.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  211.             Points.left,    /*  x - ignored for tiled windows */
  212.             Points.top,    /*  y - ignored for tiled windows */
  213.             Points.right,     /* cx - ignored for tiled windows */
  214.             Points.bottom,      /* cy - ignored for tiled windows */
  215.             (HWND)hWnd,       /*parent */
  216.             (HMENU)IDC_AUDIO,    /* use class menu */
  217.             (HANDLE)hInstance, /* handle to window instance */
  218.                         (LPSTR)NULL        /* no params to pass on */
  219.             );
  220.      
  221.      // Initialize the lpDevice3 memory which is associated with button1 on the first page.
  222.      
  223.      InitDeviceVars(lpDevice3);
  224.      
  225.      // retrieve the device information for button3 as well as where the button is located in the Points structure.
  226.      
  227.      GetStuffFromIni(lpDevice3,3,&Points);
  228.                                   
  229.      // Create the owner draw button representing button3 on the first page.  Use the coordinates retrieved
  230.      // from the playvfw.ini file.                             
  231.                                   
  232.      lpDevice3->hWnd = CreateWindow((LPSTR)"button",
  233.             (LPSTR)"Video Button",
  234.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  235.             Points.left,   /*  x - ignored for tiled windows */
  236.             Points.top,    /*  y - ignored for tiled windows */
  237.             Points.right,     /* cx - ignored for tiled windows */
  238.             Points.bottom,      /* cy - ignored for tiled windows */
  239.             (HWND)hWnd,       /*parent */
  240.             (HMENU)IDC_VIDEO,    /* use class menu */
  241.             (HANDLE)hInstance, /* handle to window instance */
  242.                         (LPSTR)NULL        /* no params to pass on */
  243.             );
  244.                                 
  245.      // Initialize the lpDevice4 memory which is associated with button4 on the first page.                           
  246.                                 
  247.      InitDeviceVars(lpDevice4);                    
  248.      
  249.      // retrieve the device information for button4 as well as where the button is located in the Points structure.
  250.  
  251.      GetStuffFromIni(lpDevice4,4,&Points);              
  252.      
  253.      // Create the owner draw button representing button4 on the first page.  Use the coordinates retrieved
  254.      // from the playvfw.ini file.
  255.  
  256.      lpDevice4->hWnd = CreateWindow((LPSTR)"button",
  257.             (LPSTR)"Animation Button",
  258.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  259.             Points.left,   /*  x - ignored for tiled windows */
  260.             Points.top,    /*  y - ignored for tiled windows */
  261.             Points.right,     /* cx - ignored for tiled windows */
  262.             Points.bottom,      /* cy - ignored for tiled windows */
  263.             (HWND)hWnd,       /*parent */
  264.             (HMENU)IDC_ANIMATION,        /* use class menu */
  265.             (HANDLE)hInstance, /* handle to window instance */
  266.                         (LPSTR)NULL        /* no params to pass on */
  267.             );
  268.                                 
  269.      // Initialize the lpDevice5 memory which is associated with button5 on the first page.                           
  270.                                 
  271.      InitDeviceVars(lpDevice5);
  272.  
  273.      // retrieve the device information for button5 as well as where the button is located in the Points structure. 
  274.  
  275.      GetStuffFromIni(lpDevice5,5,&Points);               
  276.      
  277.      // Create the owner draw button representing button5 on the first page.  Use the coordinates retrieved
  278.      // from the playvfw.ini file.
  279.  
  280.      lpDevice5->hWnd = CreateWindow((LPSTR)"button",
  281.             (LPSTR)"Graphics Button",
  282.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  283.             Points.left,   /*  x - ignored for tiled windows */
  284.             Points.top,    /*  y - ignored for tiled windows */
  285.             Points.right,     /* cx - ignored for tiled windows */
  286.             Points.bottom,      /* cy - ignored for tiled windows */
  287.             (HWND)hWnd,       /*parent */
  288.             (HMENU)IDC_GRAPHICS,       /* use class menu */
  289.             (HANDLE)hInstance, /* handle to window instance */
  290.                         (LPSTR)NULL        /* no params to pass on */
  291.                         );
  292.      
  293.      // Initialize the lpDevice6 memory which is associated with button6 on the first page.
  294.      
  295.      InitDeviceVars(lpDevice6);                    
  296.      
  297.      // retrieve the device information for button6 as well as where the button is located in the Points structure.
  298.  
  299.      GetStuffFromIni(lpDevice6,6,&Points);               
  300.      
  301.      // Create the owner draw button representing button6 on the first page.  Use the coordinates retrieved
  302.      // from the playvfw.ini file.
  303.  
  304.      lpDevice6->hWnd = CreateWindow((LPSTR)"button",
  305.             (LPSTR)"Help Button",
  306.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  307.             Points.left ,    /*  x - ignored for tiled windows */
  308.             Points.top,    /*  y - ignored for tiled windows */
  309.             Points.right,     /* cx - ignored for tiled windows */
  310.             Points.bottom,      /* cy - ignored for tiled windows */
  311.             (HWND)hWnd,       /*parent */
  312.             (HMENU)IDC_HELP,       /* use class menu */
  313.             (HANDLE)hInstance, /* handle to window instance */
  314.                         (LPSTR)NULL        /* no params to pass on */
  315.             );
  316.      
  317.      
  318.     // retrieve the device information for button7 which is the initial screen button
  319.     // as well as where the button is located in the Points structure.
  320.      
  321.      GetStuffFromIni(lpDevice7,7,&Points);
  322.                             
  323.      // make initial window coordinates relative to Bitmaps left top corner.
  324.                             
  325.      Points.left+=BmpPoints.left;
  326.      Points.top+=BmpPoints.top; 
  327.                                                        
  328.      // Create the owner draw button representing the owner draw button on the initial page.  Use the 
  329.      // coordinates retrieved from the playvfw.ini file.                                                  
  330.                                                        
  331.      lpDevice7->hWnd = CreateWindow((LPSTR)"button",
  332.             (LPSTR)"LargeButton",
  333.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  334.             Points.left ,    /*  x - ignored for tiled windows */
  335.             Points.top,    /*  y - ignored for tiled windows */
  336.             Points.right,     /* cx - ignored for tiled windows */
  337.             Points.bottom,      /* cy - ignored for tiled windows */
  338.             (HWND)hWnd,       /*parent */
  339.             (HMENU)IDC_VIDWIN,     /* use class menu */
  340.             (HANDLE)hInstance, /* handle to window instance */
  341.                         (LPSTR)NULL        /* no params to pass on */
  342.             );
  343.  
  344.  
  345.        // show the initial video window.
  346.  
  347.        ShowWindow(lpDevice7->hWnd,SW_SHOWNORMAL);
  348.                                          
  349.        // play the initial audio if there is an audio device ID (nothing failed) and if we haven't been told 
  350.        // not to play the audio.  Either in the ini file or there is no sound device.                                  
  351.                                          
  352.        if (lpDevice7->bPlayAudio)      
  353.              if (lpDevice7->wAudioDeviceID)           
  354.                    PlayWaveFile(lpDevice7->wAudioDeviceID);
  355.                           
  356.        // play the initial video if there is a VFW device ID (nothing failed) and if we haven't been told to 
  357.        // not play the video in the ini file.                   
  358.                           
  359.        if (lpDevice7->bPlayVideo)            
  360.              if (lpDevice7->wDeviceID)            
  361.                    PlayVFWFile(hWnd,lpDevice7->hWnd,lpDevice7->wDeviceID);
  362.        
  363.        // Set that the video is playing.  Therefore if the cursor does not move off of the button the video
  364.        // will continue to play.  
  365.        
  366.        lpDevice7->bVideoPlaying=TRUE;
  367.  
  368.      
  369.  
  370. return TRUE;
  371.  
  372. }
  373.  
  374. /****************************************************************************
  375.  
  376.     FUNCTION  : CreateVideoWindow(int)
  377.  
  378.     PURPOSE   : This function creates the video window used on page 2 and creates the edit control
  379.                 also used on page 2. It also creates the Video Playback Control as well as reads the
  380.                 text into the edit control.
  381.     
  382.     COMMENTS  : 
  383.  
  384.     HISTORY   : Created by Steven Molstad 7/25/93
  385.  
  386. ****************************************************************************/ 
  387.  
  388. BOOL FAR PASCAL CreateVideoWindow(nButton)
  389. int nButton;
  390. {
  391.        
  392.        char szIniName[11];       
  393.        RECT Points;
  394.        RECT Points2; 
  395.        
  396.       
  397.        HDC hTempDC;
  398.        DLGPROC dlgProc;
  399.  
  400.        wsprintf(szIniName,"button%d",nButton);
  401.            
  402.        // points refers to the VidWin, points2 refers to the control, points3 refers to the edit control.
  403.            
  404.         GetVidWinFromIni(lpDevice9,9,&Points,&Points2,&Points3,szIniName);
  405.        
  406.             lpDevice9->hWnd = CreateWindow((LPSTR)"VidWin",
  407.                                    (LPSTR)"Video Window",
  408.                                    WS_CHILD | WS_CLIPSIBLINGS,
  409.                                    Points.left ,    /*  x - ignored for tiled windows */
  410.                                    Points.top,    /*  y - ignored for tiled windows */
  411.                                    Points.right,     /* cx - ignored for tiled windows */
  412.                                    Points.bottom,      /* cy - ignored for tiled windows */
  413.                                    (HWND)hWndMain,        /*parent */
  414.                                    (HMENU)NULL,    /* use class menu */
  415.                                    (HANDLE)hInst, /* handle to window instance */
  416.                                    (LPSTR)NULL       /* no params to pass on */
  417.                                    );
  418.             
  419.             hWndEdit = CreateWindow((LPSTR)"Edit",
  420.                                    (LPSTR)"",
  421.                                    WS_CHILD | WS_CLIPSIBLINGS | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,
  422.                                    Points3.left ,    /*  x - ignored for tiled windows */
  423.                                    Points3.top,    /*  y - ignored for tiled windows */
  424.                                    Points3.right,     /* cx - ignored for tiled windows */
  425.                                    Points3.bottom,      /* cy - ignored for tiled windows */
  426.                                    (HWND)hWndMain,        /*parent */
  427.                                    (HMENU)IDC_EDIT,    /* use class menu */
  428.                                    (HANDLE)hInst, /* handle to window instance */
  429.                                    (LPSTR)NULL       /* no params to pass on */
  430.                                    );   
  431.                                    
  432.         //ReadTextFileIntoEdit();
  433.  
  434.         // Get a Device context from the video playback window an update the video in that window.   
  435.  
  436.         hTempDC=GetDC(lpDevice9->hWnd);
  437.  
  438.         UpdateVFW(lpDevice9->wDeviceID,hTempDC);
  439.  
  440.         ReleaseDC(lpDevice9->hWnd,hTempDC);
  441.         
  442.         // Show the window and create the modeless dialog box for the Video Playback Control.  
  443.  
  444.         ShowWindow(lpDevice9->hWnd, SW_SHOWNORMAL ); 
  445.             
  446.         dlgProc=(DLGPROC)MakeProcInstance(ButtonBarProc,hInst);
  447.             
  448.         hWndButtonBar=CreateDialog(hInst,MAKEINTRESOURCE(BUTTONBAR),hWndMain,dlgProc);         
  449.         
  450.         // Position and show the modeless dialog box for the video playback conrtol.
  451.  
  452.         SetWindowPos(hWndButtonBar,(HWND) NULL,Points2.left,Points2.top,Points2.right,Points2.bottom,SWP_NOACTIVATE | SWP_NOZORDER);
  453.         
  454.         // Changed my mind, don't show the button bar at this point since it could screw things up
  455.         // seems to be bringing up random avi movies when it is initially shown.
  456.         
  457.         ShowWindow(hWndButtonBar,SW_HIDE);
  458.             
  459.         
  460.      return FALSE;
  461.  
  462. /****************************************************************************
  463.  
  464.     FUNCTION    : InitDeviceVars(LPDEVICESTRUCT)
  465.  
  466.     PURPOSE   :   Initialize all the elements of the device structure.
  467.     
  468.     COMMENTS  : 
  469.  
  470.     HISTORY   :  Created by Steven Molstad 7/15/93.
  471.  
  472. ****************************************************************************/ 
  473.  
  474. BOOL FAR PASCAL InitDeviceVars(lpDevice)
  475. LPDEVICESTRUCT lpDevice;
  476. {
  477.       lpDevice->bVideoPlaying=FALSE;
  478.       lpDevice->bAudioPlaying=FALSE;
  479.       lpDevice->bVideoPaused=FALSE;
  480.       lpDevice->bButtonDown=FALSE;
  481.       lpDevice->bRButtonClicked=FALSE;
  482.  
  483. return TRUE;
  484. }
  485.  
  486. /****************************************************************************
  487.  
  488.     FUNCTION  : Morph(LPDEVICESTRUCT,int)
  489.  
  490.     PURPOSE   : Retrieve the information for and create the morph window.  This includes opening the AVI
  491.                 file for the morph.
  492.     
  493.     COMMENTS  : 
  494.  
  495.     HISTORY   : Created by Steven Molstad 8/15/93.
  496.  
  497. ****************************************************************************/ 
  498.  
  499. BOOL FAR PASCAL Morph(lpDevice,nWhichButton)
  500. LPDEVICESTRUCT lpDevice;
  501. int nWhichButton;
  502. {
  503.      RECT Points;
  504.  
  505.  
  506.      GetPG2FromIni(lpDevice,nWhichButton,&Points,"morph");
  507.  
  508.  
  509.      lpDevice->hWnd = CreateWindow((LPSTR)"button",
  510.             (LPSTR)"MorphButton",
  511.             WS_CHILD | BS_OWNERDRAW | WS_CLIPSIBLINGS,
  512.             Points.left ,    /*  x - ignored for tiled windows */
  513.             Points.top,    /*  y - ignored for tiled windows */
  514.             Points.right,     /* cx - ignored for tiled windows */
  515.             Points.bottom,      /* cy - ignored for tiled windows */
  516.             (HWND)hWndMain,        /*parent */
  517.             (HMENU)IDC_MORPH,    /* use class menu */
  518.             (HANDLE)hInst, /* handle to window instance */
  519.             (LPSTR)NULL       /* no params to pass on */
  520.             );
  521.  
  522.      
  523.      
  524.      ShowWindow(lpDevice->hWnd, SW_SHOWNORMAL );     
  525.  
  526.      return TRUE;
  527.  
  528. }
  529.  
  530. /****************************************************************************
  531.  
  532.     FUNCTION   : DrawControl(HWND,LPDRAWITEMSTRUCT)
  533.  
  534.     PURPOSE   :  This function is called in response to a WM_DRAWITEM message.  This function takes care
  535.                  of loading the VFW file into the button when the page initialy is drawn.  Or when any of
  536.                  the buttons need to be re-drawn. 
  537.     
  538.     COMMENTS  : 
  539.  
  540.     HISTORY   :  Created by Steven Molstad 8/15/93
  541.  
  542. ****************************************************************************/ 
  543.  
  544. void DrawControl(HWND hWnd, LPDRAWITEMSTRUCT lpInfo)
  545. {
  546.     
  547.        if (lpInfo->CtlType != ODT_BUTTON) return;
  548.  
  549.        // Load the bitmap for the image
  550.  
  551.        switch(lpInfo->CtlID)
  552.         {
  553.  
  554.          case IDC_TEXT:
  555.                if (bIsPage1 || bIsPage2)
  556.                       {
  557.                        textrect=lpInfo->rcItem;
  558.                        if (lpInfo->itemAction == ODA_DRAWENTIRE)
  559.                              {
  560.                               UpdateVFW(lpDevice1->wDeviceID,lpInfo->hDC);
  561.                              }
  562.  
  563.                       } // bIsPage1
  564.           break;
  565.  
  566.          case IDC_AUDIO:
  567.                if (bIsPage1 || bIsPage2)
  568.                       {                   
  569.                        audiorect=lpInfo->rcItem;
  570.  
  571.                        if (lpInfo->itemAction == ODA_DRAWENTIRE)
  572.                             {
  573.                              UpdateVFW(lpDevice2->wDeviceID,lpInfo->hDC);
  574.                             }
  575.                       } // bIsPage1
  576.           break;
  577.  
  578.  
  579.  
  580.          case IDC_VIDEO:
  581.             if (bIsPage1 || bIsPage2)
  582.                   {             
  583.                    videorect=lpInfo->rcItem;
  584.                    if (lpInfo->itemAction == ODA_DRAWENTIRE)
  585.                          {
  586.                           UpdateVFW(lpDevice3->wDeviceID,lpInfo->hDC);
  587.                          }
  588.  
  589.                   } // bIsPage1
  590.          break;
  591.  
  592.          case IDC_ANIMATION:
  593.              if (bIsPage1 || bIsPage2)
  594.                   {
  595.                    animationrect=lpInfo->rcItem;
  596.                    if (lpInfo->itemAction == ODA_DRAWENTIRE)
  597.                          {
  598.                           UpdateVFW(lpDevice4->wDeviceID,lpInfo->hDC);
  599.                          }
  600.                   }// bIsPage1
  601.          break;
  602.  
  603.  
  604.          case IDC_GRAPHICS:
  605.             if (bIsPage1 || bIsPage2)
  606.                 {
  607.                  graphicsrect=lpInfo->rcItem;
  608.                  if (lpInfo->itemAction == ODA_DRAWENTIRE)
  609.                        {
  610.                         UpdateVFW(lpDevice5->wDeviceID,lpInfo->hDC);
  611.                        }
  612.                   }//bIsPage1
  613.          break;
  614.  
  615.          case IDC_HELP:
  616.             if (bIsPage1 || bIsPage2)
  617.                   {
  618.                    helprect=lpInfo->rcItem;
  619.                    if (lpInfo->itemAction == ODA_DRAWENTIRE)
  620.                          {
  621.                           UpdateVFW(lpDevice6->wDeviceID,lpInfo->hDC);                    
  622.                          }
  623.                   }//bIsPage1
  624.          break;
  625.  
  626.          case IDC_VIDWIN:
  627.             if (bIsPage0)
  628.                 {              
  629.                 helprect=lpInfo->rcItem;
  630.                 if (lpInfo->itemAction == ODA_DRAWENTIRE)
  631.                       {
  632.                        UpdateVFW(lpDevice7->wDeviceID,lpInfo->hDC);
  633.                       }                                              
  634.                       
  635.                 // if the initial button was pressed set bButtonDown to TRUE. 
  636.                 
  637.                 if (lpInfo->itemAction == ODA_SELECT)
  638.                       {
  639.                        if(lpDevice7->bButtonDown)
  640.                              lpDevice7->bButtonDown=FALSE;
  641.                        else
  642.                              lpDevice7->bButtonDown=TRUE;
  643.                       } // if ODA_SELECT
  644.                 } //bIsPage0
  645.          break;
  646.  
  647.          case IDC_MORPH:
  648.               helprect=lpInfo->rcItem;
  649.               if (lpInfo->itemAction == ODA_DRAWENTIRE)
  650.                    {               
  651.                    UpdateVFW(lpDevice8->wDeviceID,lpInfo->hDC);
  652.                    }
  653.  
  654.               if (lpInfo->itemAction == ODA_SELECT)
  655.                    {
  656.                     if(lpDevice8->bButtonDown)
  657.                            lpDevice8->bButtonDown=FALSE;
  658.                     else
  659.                            lpDevice8->bButtonDown=TRUE;
  660.                 }
  661.          break;
  662.          }
  663.  
  664.      
  665.  
  666. return;
  667. }
  668.  
  669.  
  670. /****************************************************************************
  671.  
  672.     FUNCTION  : DoNextPage(int)
  673.  
  674.     PURPOSE   : This function sets up the last page of buttons.  It takes care of opening the new VFW files.
  675.                 It also takes care of hiding the windows and setting the new window positions.
  676.     
  677.     COMMENTS  : 
  678.  
  679.     HISTORY   :
  680.  
  681. ****************************************************************************/ 
  682.  
  683.  
  684. BOOL FAR PASCAL DoNextPage(nWhichButton)
  685. int nWhichButton;
  686. {
  687.      RECT Points;
  688.      char szIniName[9];
  689.      //MSG msg;
  690.  
  691.      HideAllWindows();
  692.  
  693.      wsprintf(szIniName,"Button%d",nWhichButton);
  694.  
  695.      InitDeviceVars(lpDevice1);
  696.  
  697.      GetPG2FromIni(lpDevice1,1,&Points,szIniName);
  698.      
  699.      ShowWindow( lpDevice1->hWnd, SW_SHOWNORMAL );
  700.      SetWindowPos(lpDevice1->hWnd,(HWND) NULL,Points.left,Points.top,Points.right,Points.bottom,SWP_NOACTIVATE | SWP_NOZORDER);
  701.  
  702.      InitDeviceVars(lpDevice2);
  703.  
  704.      GetPG2FromIni(lpDevice2,2,&Points,szIniName);
  705.    
  706.      SetWindowPos(lpDevice2->hWnd,(HWND) NULL,Points.left,Points.top,Points.right,Points.bottom,SWP_NOACTIVATE | SWP_NOZORDER);
  707.      ShowWindow( lpDevice2->hWnd, SW_SHOWNORMAL );
  708.  
  709.      InitDeviceVars(lpDevice3);
  710.  
  711.      GetPG2FromIni(lpDevice3,3,&Points,szIniName);
  712.     
  713.      SetWindowPos(lpDevice3->hWnd,(HWND) NULL,Points.left,Points.top,Points.right,Points.bottom,SWP_NOACTIVATE | SWP_NOZORDER);
  714.      ShowWindow( lpDevice3->hWnd, SW_SHOWNORMAL );
  715.  
  716.      InitDeviceVars(lpDevice4);
  717.  
  718.      GetPG2FromIni(lpDevice4,4,&Points,szIniName);
  719.  
  720.      SetWindowPos(lpDevice4->hWnd,(HWND) NULL,Points.left,Points.top,Points.right,Points.bottom,SWP_NOACTIVATE | SWP_NOZORDER);
  721.      ShowWindow( lpDevice4->hWnd, SW_SHOWNORMAL );
  722.       
  723.      CreateVideoWindow(nWhichButton);
  724.       
  725.  
  726.      bIsPage2=TRUE;
  727.      bIsPage1=FALSE;
  728.      bButtonDown=TRUE;
  729.  
  730. return TRUE;
  731. }
  732.  
  733.  
  734. /****************************************************************************
  735.  
  736.     FUNCTION    : DoPage1()
  737.  
  738.     PURPOSE   :  This function takes care of setting up the first page of buttons.  It shows all video buttons
  739.                  which were previously setup with VFW files.
  740.     
  741.     COMMENTS  : 
  742.  
  743.     HISTORY   :  Created by Steven Molstad 8/1/93
  744.  
  745. ****************************************************************************/ 
  746.  
  747. BOOL FAR PASCAL DoPage1()
  748.  
  749. {   
  750.    
  751.     
  752.     BOOL bReturn;                
  753.     
  754.     InvalidateRect(hWndMain,NULL,TRUE);
  755.     
  756.   
  757.          bIsPage0=FALSE;
  758.          bIsPage1=TRUE;
  759.  
  760.          ShowWindow(lpDevice1->hWnd,SW_SHOWNORMAL);
  761.          ShowWindow(lpDevice2->hWnd,SW_SHOWNORMAL);
  762.          ShowWindow(lpDevice3->hWnd,SW_SHOWNORMAL);
  763.          ShowWindow(lpDevice4->hWnd,SW_SHOWNORMAL);
  764.          ShowWindow(lpDevice5->hWnd,SW_SHOWNORMAL);
  765.          ShowWindow(lpDevice6->hWnd,SW_SHOWNORMAL);
  766.          ShowWindow(lpDevice7->hWnd,SW_HIDE);
  767.  
  768.        
  769.  
  770.          bReturn = CloseWaveFile(lpDevice7->wAudioDeviceID);
  771.         
  772.  
  773.          bReturn = CloseVFWFile(lpDevice7->wDeviceID); 
  774.            
  775.          
  776.     return TRUE;
  777. }
  778.  
  779.  
  780. /****************************************************************************
  781.  
  782.     FUNCTION  : ReturnDeviceError(LPSTR,HANDLE,HANDLE,HANDLE,HANDLE,HANDLE)
  783.  
  784.     PURPOSE   : This function is used to return errors when a file cannot be found.
  785.     
  786.     COMMENTS  : 
  787.  
  788.     HISTORY   : Created by Steven Molstad 8/1/93
  789.  
  790. ****************************************************************************/ 
  791.  
  792. void FAR PASCAL ReturnDeviceError(LPSTR lpBuffer,HANDLE hFileName,HANDLE hSection,HANDLE hBuffer,HANDLE hExeName,HANDLE hAlias)
  793. {
  794.        HANDLE hBuf;
  795.        LPSTR lpBuf;
  796.  
  797.        hBuf=GlobalAlloc(GHND,255);
  798.        if(!hBuf)
  799.         return;
  800.  
  801.        lpBuf=GlobalLock(hBuf);
  802.  
  803.        if (!lpBuf)
  804.            return;
  805.  
  806.        wsprintf(lpBuf,"The %s file could not be open.  Check that the file exists and that it is correct in the initialization file",lpBuffer);
  807.        MessageBox(hWndMain,lpBuf,"ERROR",MB_OK);
  808.  
  809.        GlobalUnlock(hFileName);
  810.        GlobalUnlock(hSection);
  811.        GlobalUnlock(hBuffer);
  812.        GlobalUnlock(hExeName);
  813.        GlobalUnlock(hAlias);
  814.        GlobalUnlock(hBuf);
  815.  
  816.        GlobalFree(hFileName);
  817.        GlobalFree(hSection);
  818.        GlobalFree(hBuffer);
  819.        GlobalFree(hExeName);
  820.        GlobalFree(hAlias);
  821.        GlobalFree(hBuf);
  822.  
  823. return;
  824. }
  825.  
  826.  
  827.  
  828.